/**
 * Created by Administrator on 2016/3/2.
 *游戏结束计数页面
 */
gpNamespace.JsLayer = cc.Layer.extend({
	players: [],
	label:null,

	winIndex: null,
	//游戏积分
	score: [],
	//倍数
	userMultiple:[],
	//结束剩余张数
	remainCardCount:[],
	//具体牌（不用）
	remainCards:[],
	//输赢张数
	winorloseCardsCount:[],
	num:9,
	timeShow:null,
	namePosition: [cc.p(339,500),cc.p(520,300),cc.p(183,300)],
	winPosition: [],
	scorePosition: [],
	cardsPosition: [],
	startPoint: cc.p(640, 170),
	chuPoint: cc.p(0, 0),
	
	ctor: function (players, winIndex, gameScore, userMultiple, remainCardCount, remainCards, winorloseCardsCount) {
    	this._super();
    	
    	this.players = players;
    	this.winIndex = winIndex;
    	this.score = gameScore;
    	this.userMultiple = userMultiple;
    	this.remainCardCount = remainCardCount;
    	this.remainCards = remainCards;
    	this.winorloseCardsCount = winorloseCardsCount;

    	this.init();
    },
    
    init: function () {
//    	cc.spriteFrameCache.addSpriteFrames (gpNamespace.jsRes.Js_plist);
    	cc.spriteFrameCache.addSpriteFrames (gpNamespace.pdkjiesuanRes.Pdkjiesuan_plist);
		gpNamespace.playerLeaved = false;
//    	for (var a = 0; a < 4; a++) {
//    		this.namePosition.push(cc.p(30, 98 - 130 * a));
//    		this.winPosition.push(cc.p(260, 98 - 130 * a));
//    		this.cardsPosition.push(cc.p(30, 98 - 130 * a));
//    		//this.scorePosition.push(cc.p(435, 98 - 40 * a));
//    		this.scorePosition.push(cc.p(435, 112 - 130 * a));
//    	}
    	
    	cc.log("进入init界面===============================");

        //背景图层
        var background = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_background);
        background.attr({
            x: 307+background.width/2 ,
            y: 12+background.height/2 ,
            anchorX: 0.5,
            anchorY: 0.5
        });
        this.addChild(background);
        if(this.winIndex==0){
        	//胜利top
        	var topwin = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_top_win);
        	topwin.attr({
        		x:646,
        		y:625
        	});
        	this.addChild(topwin);
        }else{
        	//失败top
        	var toplose = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_top_lose);
        	toplose.attr({
        		x:646,
        		y:625
        	});
        	this.addChild(toplose);
        }

        //循环
        for (var a = 0; a < 3; a++) {
        	var player = this.players[a];
        	cc.log("this.players[a]" + player);
        
        	if(this.winIndex==0){
        		if(a == 0){
        			//昵称
        			var label1 = new cc.LabelTTF(player.userItem.nickName, "Arial", 30);//Arial 25
        			label1.attr({
        				x: this.namePosition[0].x ,
        				y: this.namePosition[0].y ,
        			});
        			label1.setColor(cc.color(253, 212, 98));
        			background.addChild(label1);
        			//底分两字
        			var difen = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_difen);
        			difen.attr({
        				x: this.namePosition[0].x-40 ,
        				y: this.namePosition[0].y -40,
        			});
        			background.addChild(difen);
        			//底分
        			var difenNum = new tyNamespace.NumLayer(gpNamespace.difen, 18, 13);
        			difenNum.attr({
        				x: this.namePosition[0].x +30,
        				y: this.namePosition[0].y -40,
        			});
        			difenNum.setColor(cc.color(253, 212, 98));
        			background.addChild(difenNum);

        			//剩余牌的张数   remainCardCount
//        			var remainCount = new cc.LabelTTF(this.remainCardCount[a].toString(), "Consolas", 35);
        			var remainCount = new tyNamespace.NumLayer(this.winorloseCardsCount[a].toString(), 18, 13);
        			cc.log("this.remainCardCount[a]----------" + this.winorloseCardsCount[a]);
        			remainCount.attr({
        				x: this.namePosition[0].x+40,
        				y: this.namePosition[0].y-80,
        			});
        			background.addChild(remainCount);
        			//牌的张数几个字
        			var paishu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_win_zhang);
        			paishu.attr({
        				x: this.namePosition[0].x,
        				y: this.namePosition[0].y-80,
        			});
        			background.addChild(paishu);
        		}else{
        			//昵称
        			var label1 = new cc.LabelTTF(player.userItem.nickName, "Arial", 30);//Arial 25
        			label1.attr({
        				x: this.namePosition[a].x ,
        				y: this.namePosition[a].y ,
        			});
        			background.addChild(label1);
        			//倍数两字
        			var bieshu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_bieshu);
        			bieshu.attr({
        				x: this.namePosition[a].x-50 ,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(bieshu)
        			//倍的乘号  userMultiple
        			var cheng = new cc.Sprite("#sz_cdd_js_012u.png");
        			cheng.attr({
        				x: this.namePosition[a].x ,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(cheng);
        			//倍的数字
        			var bei = new tyNamespace.NumLayer(this.userMultiple[a], 18, 0);
//        			var bei = new cc.LabelTTF(this.userMultiple[a], "Consolas", 35);
        			bei.attr({
        				x: this.namePosition[a].x +30,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(bei);

        			//剩余牌的张数   remainCardCount
        			var remainCount = new tyNamespace.NumLayer(this.remainCardCount[a].toString(), 18, 0);
        			cc.log("this.remainCardCount[a]----------" + this.remainCardCount[a]);
        			remainCount.attr({
        				x: this.namePosition[a].x+40,
        				y: this.namePosition[a].y-80,
        			});
        			background.addChild(remainCount);
        			//牌的张数几个字
        			var paishu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_lose_zhang);
        			paishu.attr({
        				x: this.namePosition[a].x,
        				y: this.namePosition[a].y-80,
        			});
        			background.addChild(paishu);
        		}
        		
        	}else if (this.winIndex == 1){
        		if(a == 1){
        			//昵称
        			var label1 = new cc.LabelTTF(player.userItem.nickName, "Arial", 30);//Arial 25
        			label1.attr({
        				x: this.namePosition[1].x ,
        				y: this.namePosition[1].y ,
        			});
        			label1.setColor(cc.color(253, 212, 98));
        			background.addChild(label1);
        			//胜利两字
        			var win = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_win);
        			win.attr({
        				x:this.namePosition[1].x,
        				y:this.namePosition[1].y-40,
        			});
        			background.addChild(win);

        			//剩余牌的张数   remainCardCount
        			var remainCount = new tyNamespace.NumLayer(this.winorloseCardsCount[a].toString(), 18, 13);
        			cc.log("this.remainCardCount[a]----------" + this.winorloseCardsCount[a]);
        			remainCount.attr({
        				x: this.namePosition[1].x+40,
        				y: this.namePosition[1].y-80,
        			});
        			background.addChild(remainCount);
        			//牌的张数几个字
        			var paishu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_win_zhang);
        			paishu.attr({
        				x: this.namePosition[1].x,
        				y: this.namePosition[1].y-80,
        			});
        			background.addChild(paishu);
        		}else{
        			//昵称
        			var label1 = new cc.LabelTTF(player.userItem.nickName, "Arial", 30);//Arial 25
        			label1.attr({
        				x: this.namePosition[a].x ,
        				y: this.namePosition[a].y ,
        			});
        			background.addChild(label1);
        			//倍数两字
        			var bieshu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_bieshu);
        			bieshu.attr({
        				x: this.namePosition[a].x-50 ,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(bieshu)
        			//倍的乘号  userMultiple
        			var cheng = new cc.Sprite("#sz_cdd_js_012u.png");
        			cheng.attr({
        				x: this.namePosition[a].x ,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(cheng);
        			//倍的数字
        			var bei = new tyNamespace.NumLayer(this.userMultiple[a], 18, 0);
        			//var bei = new cc.LabelTTF(this.userMultiple[a], "Consolas", 35);
        			bei.attr({
        				x: this.namePosition[a].x +30,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(bei);
        			
        			//剩余牌的张数   remainCardCount
        			var remainCount = new tyNamespace.NumLayer(this.remainCardCount[a].toString(), 18, 0);
        			cc.log("this.remainCardCount[a]----------" + this.remainCardCount[a]);
        			remainCount.attr({
        				x: this.namePosition[a].x+40,
        				y: this.namePosition[a].y-80,
        			});
        			background.addChild(remainCount);
        			//牌的张数几个字
        			var paishu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_lose_zhang);
        			paishu.attr({
        				x: this.namePosition[a].x,
        				y: this.namePosition[a].y-80,
        			});
        			background.addChild(paishu);
        		}
        	}else{
        		if(a == 2){
        			//昵称
        			var label1 = new cc.LabelTTF(player.userItem.nickName, "Arial", 30);//Arial 25
        			label1.attr({
        				x: this.namePosition[2].x ,
        				y: this.namePosition[2].y ,
        			});
        			label1.setColor(cc.color(253, 212, 98));
        			background.addChild(label1);
        			//胜利两字
        			var win = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_win);
        			win.attr({
        				x:this.namePosition[2].x,
        				y:this.namePosition[2].y-40,
        			});
        			background.addChild(win);
        			
        			//剩余牌的张数   remainCardCount
        			var remainCount = new tyNamespace.NumLayer(this.winorloseCardsCount[a].toString(), 18, 13);
        			cc.log("this.remainCardCount[a]----------" + this.winorloseCardsCount[a]);
        			remainCount.attr({
        				x: this.namePosition[2].x+40,
        				y: this.namePosition[2].y-80,
        			});
        			background.addChild(remainCount);
        			//牌的张数几个字
        			var paishu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_win_zhang);
        			paishu.attr({
        				x: this.namePosition[2].x,
        				y: this.namePosition[2].y-80,
        			});
        			background.addChild(paishu);
        		}else{
        			//昵称
        			var label1 = new cc.LabelTTF(player.userItem.nickName, "Arial", 30);//Arial 25
        			label1.attr({
        				x: this.namePosition[a].x ,
        				y: this.namePosition[a].y ,
        			});
        			background.addChild(label1);
        			//倍数两字
        			var bieshu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_bieshu);
        			bieshu.attr({
        				x: this.namePosition[a].x-50 ,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(bieshu)
        			//倍的乘号  userMultiple
        			var cheng = new cc.Sprite("#sz_cdd_js_012u.png");
        			cheng.attr({
        				x: this.namePosition[a].x ,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(cheng);
        			//倍的数字
        			//var bei = new cc.LabelTTF(this.userMultiple[a], "Consolas", 35);
        			var bei = new tyNamespace.NumLayer(this.userMultiple[a], 18, 0);
        			bei.attr({
        				x: this.namePosition[a].x +30,
        				y: this.namePosition[a].y -40,
        			});
        			background.addChild(bei);

        			//剩余牌的张数   remainCardCount
        			var remainCount = new tyNamespace.NumLayer(this.remainCardCount[a].toString(), 18, 0);
        			cc.log("this.remainCardCount[a]----------" + this.remainCardCount[a]);
        			remainCount.attr({
        				x: this.namePosition[a].x+40,
        				y: this.namePosition[a].y-80,
        			});
        			background.addChild(remainCount);
        			//牌的张数几个字
        			var paishu = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_lose_zhang);
        			paishu.attr({
        				x: this.namePosition[a].x,
        				y: this.namePosition[a].y-80,
        			});
        			background.addChild(paishu);
        		}
        	}
        	
        	//分数正负 (+-号)
        	var score = this.score[a];
        	
        	var GoldPic = new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_gold);
        	GoldPic.attr({
        		x: this.namePosition[a].x-105,
        		y: this.namePosition[a].y-122 ,
        	});
        	background.addChild(GoldPic);
        	//金币正负
        	var score = this.score[a];
        	//减号
        	var zhengfu = new cc.Sprite("#sz_cdd_js_010u.png");  
        	if (score >=0) {
        		//加号
        		zhengfu = new cc.Sprite("#sz_cdd_js_024u.png");  
        	}
        	zhengfu.attr({
        		x: this.namePosition[a].x -105+55,
        		y: this.namePosition[a].y-122
        	});
        	background.addChild(zhengfu);
        	zhengfu.setScale(1);

        	for (var b = 0; b < Math.abs(score).toString().length; b++) {
        		var str = tyNamespace.FullZero((parseInt(Math.abs(score).toString().substr(b, 1)) + 13).toString(), 3);//白色数字转换成黄色数字
        		var strwhite = tyNamespace.FullZero((parseInt(Math.abs(score).toString().substr(b, 1))).toString(), 3);
        		var spritName = "#sz_cdd_js_" + str + "u.png";
        		if (score < 0)
        			spritName = "#sz_cdd_js_" + strwhite + "u.png";
        		var countCell = new cc.Sprite(spritName);  //层叠加效果
        		countCell.attr({
        			x: this.namePosition[a].x + b * 18-15,
        			y: this.namePosition[a].y -137,
        			anchorX:0,
        			anchorY:0
        		});
        		background.addChild(countCell);
        		countCell.setScale(1);
        	}
    	}

        //离开按钮,再来一局按钮
        //if (!currentNetManager.isMatch) {
	        var leaveBt=new cc.MenuItemSprite(
	            new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_leave),
	            new tyNamespace.maskSprite(gpNamespace.pdkjiesuan.jiesuan_leave),
	            this.quitCallbackFunction, this);
			leaveBt.setScale(0.8);
	
	        var againBt = new cc.MenuItemSprite(
	            new cc.Sprite(gpNamespace.pdkjiesuan.jiesuan_zailaiyiju),
	            new tyNamespace.maskSprite(gpNamespace.pdkjiesuan.jiesuan_zailaiyiju),
	            this.againCallbackFunction, this);
			againBt.setScale(0.8);

			var changeTableBt = new cc.MenuItemSprite(
				new cc.Sprite(gpNamespace.xinzeng.changeTableBnSmall),
				new tyNamespace.maskSprite(gpNamespace.xinzeng.changeTableBnSmall),
				this.changeTableCallbackFunction,this);
			changeTableBt.setScale(0.8);

	        var leftMenu = new cc.Menu(leaveBt, changeTableBt,againBt);
	
	        leftMenu.attr({
	            x: 340,
	            y: 70,
	        });
	        leftMenu.alignItemsHorizontallyWithPadding(35);
	        background.addChild(leftMenu,2);
			if (currentNetManager.isMatch) {
				//离开按钮,再来一局按钮是否显示
				cc.log("##leftMenu.setVisible(false);");
				leftMenu.alignItemsHorizontallyWithPadding(-35);
				leftMenu.setVisible(false);
			}
	    //}

		var timeLabel = new cc.LabelTTF("倒数    秒将自动开始下一轮","Consolas",22);
		timeLabel.setColor(cc.color(79,253,251));
		timeLabel.attr({
			x:340,
			y:120,
		})
		background.addChild(timeLabel,2);

		var timeShow = new tyNamespace.NumLayer(this.num,12,13,"sz_cdd_js_");
		timeShow.attr({
			x:255,
			y:120,
		})
		background.addChild(timeShow, 2, "timeShow");
		this.timeShow = timeShow;

		var self = this;
		this.soundEffectId = null;
		timeShow.schedule(function(){
			if(self.num <= 0){
				self.unschedule(timeShow);
			}else{
				timeShow.reloadNum(--self.num);
				if(self.num > 0 && self.num <= 3){
					self.soundEffectId = cc.audioEngine.playEffect(gpNamespace.soundRes.AlertEffect, false);
				}else{
					if(gpNamespace.DhqIsOver){
						self.setBtEnable();
						self.num = 0;
						gpNamespace.DhqIsOver = false;
					}
				}
			}
		},1);
		//设置时间
//        this.scheduleOnce(function () {
//        	xzgbNamespace.SoundManager.playEffect(xzgbNamespace.soundRes.Boom, false);
//        }, 5);
    },

    setRestTime:function(restTime){ 
    	if (restTime == 0)
    		this.label.setString("比赛结束");
    	else
    		this.label.setString("剩余" + restTime + "局");
    },

    //踢出
    kickOut:function(){
    	cc.log("kickOut");

    	var cddNet = gpNamespace.NetManager.getInstance();

    	cddNet.removeMyListeners();

    	gpNamespace.NetManager.instance = null;
    },

    againCallbackFunction: function (sender) {
    	cc.log("再来一局");
		cc.log(">>>>>>>>>>>>>>>>>subroom:"+gpNamespace.subRoom);
//    	gpNamespace.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	tyNamespace.setMenuEnable(sender);

		this.unschedule(this.timeShow);//停止倒计时
		cc.audioEngine.stopEffect(this.soundEffectId);

    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
    	if (gpNamespace.subRoom == 5) {
    		var currentGold = userInfo.gold;
    		var pochanCount = cc.sys.localStorage.getItem(gpNamespace.POCHANCOUNT);
    		if (!tyNamespace.checkStore(pochanCount))
    			pochanCount = 0;
    		
    		if (parseInt(currentGold) < 100 && parseInt(pochanCount) < 3) {
    			//xinyou.netManager.leaveRoom();

    			tyNamespace.IsPochan = true;

    			this.kickOut();
    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
    			return;
    		}

    		var oneRMB = userInfo.isBuyOne;
    		if (parseInt(currentGold) < 100 && parseInt(pochanCount) >= 3 && !oneRMB) {
    			//xinyou.netManager.leaveRoom();

    			gpNamespace.IsBuyOne = true;

    			this.kickOut();
    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
    			
    			return;
    		}

    		var limitGold = gpNamespace.roomLimitScore;
    		if (parseInt(currentGold) < parseInt(limitGold)) {
    			//xinyou.netManager.leaveRoom();

    			tyNamespace.IsLimit = true;

    			this.kickOut();

    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

    			return;
    		}

    		xinyou.netManager.sendGameMessage(gpNamespace.netStruct.SUB_C_GAMEREADY, new xinyou.ByteArray());

    		return;
    	}

    	if (gpNamespace.subRoom < 5) {
    		var currentGold = userInfo.gold;
    		var pochanCount = cc.sys.localStorage.getItem(tyNamespace.POCHANCOUNT);
    		if (!tyNamespace.checkStore(pochanCount))
    			pochanCount = 0;
    		
    		if (parseInt(currentGold) < 100 && parseInt(pochanCount) < 3) {
    			//xinyou.netManager.leaveRoom();

    			tyNamespace.IsPochan = true;

    			this.kickOut();

    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

    			return;
    		}

    		var oneRMB = userInfo.isBuyOne;
    		if (parseInt(currentGold) < 100 && parseInt(pochanCount) >= 3 && !oneRMB) {
    			//xinyou.netManager.leaveRoom();

    			tyNamespace.IsBuyOne = true;

    			this.kickOut();

    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

    			return;
    		}

    		var currentGold = userInfo.gold;
    		var limitGold = gpNamespace.roomLimitScore;
    		if (!tyNamespace.IsPochan &&  parseInt(currentGold) < parseInt(limitGold)) {
    			//xinyou.netManager.leaveRoom();

    			tyNamespace.IsLimit = true;

    			this.kickOut();

    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

    			return;
    		}
    	}

		if(gpNamespace.subRoom >= 22 && gpNamespace.subRoom <= 25){
			cc.log("兑换券赛再来一局！");
			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
			tyNamespace.setMenuEnable(sender,1);
			if(userInfo.gold < this.levalTicketArray[gpNamespace.CurrentDhqLevel-1]){
				tyNamespace.warningJumper(1, tyNamespace.WarningSectencesIndex.NoGold,function(){
					cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.CddMainScene()));
				});
				return;
			}
			this.isApplying = true;

			var dzmjNet = gpNamespace.NetManager.getInstance();
			dzmjNet.baoMingLayer = this;
			this.againBt.setEnabled(false);
			this.againBt.setOpacity(200);

			//等待中
			var armature = new ccs.Armature("loading_001u");
			armature.getAnimation().playWithIndex(0);
			armature.getAnimation().setSpeedScale(1);
			armature.setScale(1);
			armature.setAnchorPoint(0.5, 0.5);
			armature.setPosition(640, 360);
			armature.setTag(11);
			this.addChild(armature,10);

			var cddNet = gpNamespace.NetManager.getInstance();
			cddNet.baoMingLayer = this;
			xinyou.netManager.inRoom(6, gpNamespace.CurrentDhqLevel+17, 1);
			userInfo.gold = userInfo.gold - this.levalTicketArray[gpNamespace.CurrentDhqLevel-1];
			return;
		}

    	if (gpNamespace.subRoom > 5) {
    		var currentFen = currentNetManager.me.userItem.lScore;
    		var limitFen = gpNamespace.roomLimitScore;

    		if (parseInt(currentFen) < parseInt(limitFen)) {
    			//xinyou.netManager.leaveRoom();

    			tyNamespace.IsLimitFen = true;

    			this.kickOut();

    			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

    			return;
    		}
    	}

    	xinyou.netManager.sendGameMessage(gpNamespace.netStruct.SUB_C_GAMEREADY, new xinyou.ByteArray());
    },

	changeTableCallbackFunction:function(sender){

		tyNamespace.setMenuEnable(sender);

		this.unschedule(this.timeShow);//停止倒计时
		cc.audioEngine.stopEffect(this.soundEffectId);

		var currentGold = userInfo.gold;
		var pochanCount = cc.sys.localStorage.getItem(tyNamespace.POCHANCOUNT);
		if (!tyNamespace.checkStore(pochanCount))
			pochanCount = 0;

		if (parseInt(currentGold) < 100 && parseInt(pochanCount) < 3) {
//    		xinyou.netManager.leaveRoom();

			tyNamespace.IsPochan = true;

			this.kickOut();

			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

			return;
		}

		var oneRMB = userInfo.isBuyOne;
		if (parseInt(currentGold) < 100 && parseInt(pochanCount) >= 3 && !oneRMB) {
//    		xinyou.netManager.leaveRoom();

			tyNamespace.IsBuyOne = true;

			this.kickOut();

			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

			return;
		}

		var currentGold = userInfo.gold;
		var limitGold = gpNamespace.roomLimitScore;

		cc.log("游戏继续：limitGold：" + limitGold);
		cc.log("游戏继续：currentGold：" + currentGold);
		cc.log("游戏继续：tyNamespace.IsBuyOne：" + tyNamespace.IsBuyOne);
		cc.log("游戏继续：tyNamespace.IsPochan：" + tyNamespace.IsPochan);
		if (!tyNamespace.IsPochan && parseInt(currentGold) < parseInt(limitGold)) {
//    		xinyou.netManager.leaveRoom();

			tyNamespace.IsLimit = true;

			this.kickOut();

			cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

			return;
		}

//    	tyNamespace.addWaitLayer();

		var cddNet = gpNamespace.NetManager.getInstance();
		cddNet.removeMyListeners();
		gpNamespace.NetManager.instance = null;
		if(!gpNamespace.playerLeaved){
			xinyou.netManager.leaveTable();
			gpNamespace.needLeaveRoom = false;
		}

		var runningScene = cc.director.getRunningScene();
		var prepareLayer = runningScene.getChildByName(gpNamespace.GamePrepareLayerName);
		var lastGamePlayLayer = runningScene.getChildByName("gamePlayLayer");
		lastGamePlayLayer.removeAllChildren(true);
		prepareLayer.removeAllChildren(true);
		prepareLayer.init();

		var cddNet = gpNamespace.NetManager.getInstance();
		currentNetManager = cddNet;

		cddNet.addMyListeners();
//
		xinyou.netManager.sitDown();

		this.getParent().removeFromParent();
	},

    quitCallbackFunction: function (sender) {
    	cc.log("退出");

    	tyNamespace.setMenuEnable(sender);
		this.unschedule(this.timeShow);//停止倒计时
		cc.audioEngine.stopEffect(this.soundEffectId);

//    	gpNamespace.playMusic(gpNamespace.soundRes.BackgroundMusic, true);
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonBack, false);

    	var cddNet = gpNamespace.NetManager.getInstance();

    	cddNet.removeMyListeners();

    	gpNamespace.NetManager.instance = null;

		if(gpNamespace.subRoom <= 5){
			if(!gpNamespace.playerLeaved){
				xinyou.netManager.leaveTable();
				gpNamespace.needLeaveRoom = true;
			}
		}

    	var currentGold = userInfo.gold;
    	var pochanCount = cc.sys.localStorage.getItem(gpNamespace.POCHANCOUNT);
    	if (pochanCount == null && pochanCount == "" )
    		pochanCount = 0;

    	if (parseInt(currentGold) < 300 && parseInt(pochanCount) < 3) {
    		tyNamespace.IsPochan = true;

    		cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));

    		return;
    	}

    	var oneRMB = userInfo.isBuyOne;
    	if (parseInt(currentGold) < 300 && parseInt(pochanCount) >= 3 && !oneRMB) {
    		gpNamespace.IsBuyOne = true;

    		cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
    		return;
    	}

//    	cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.DdzScene()));
//    	cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
//    	var runningScene = cc.director.getRunningScene();
//    	var jdcLayer = new gpNamespace.JdcLayer();
//    	runningScene.addChild(jdcLayer);
    },
	setBtEnable:function(){
		cc.log("setBtEnable");
		this.unschedule(this.timeShow);//停止倒计时
		cc.audioEngine.stopEffect(this.soundEffectId);
		this.leftMenu.setVisible(true);
//		this.timeWords.runAction(new cc.FadeOut(1));
//		this.timeShow.numFadeOut(1);
//		this.timeShow.runAction(new cc.FadeOut(1));
	},
	onExit:function(){
		this._super();
		gpNamespace.IsInJs = false;
	}
});